using UnityEngine;
public class RoleInfo : MonoBehaviour
{
    public Animator anim; // 动画控制器
    public Collider coll; // 碰撞器
    public int hpMax = 30; // 最大生命值
    public int hp = 10; //生命值
    public HpBar hpBar;
    public float openDoorRange = 2f; //开门检测范围

    protected void Start()
    {
        if (hpBar)
        {
            hp = hpMax;
            setHp();
        }
    }

    /// <summary>受到伤害</summary>
    /// <param name="damage">伤害值</param>
    public void hurt(int damage)
    {
        setHp(-damage);
    }

    /// <summary>设置生命值</summary>
    /// <param name="num">数值可以是 正/负 数</param>
    public void setHp(int num = 0)
    {
        hp += num;  // 扣血
        if (hp < 0) hp = 0;
        if (hpBar) hpBar.SetHp(hpMax, hp);
        if (hp == 0)
        {
            die();
            Debug.Log(gameObject.name + "死亡");
        }
    }
    /// <summary>切换武器</summary>
    public virtual void setGun(int id) { }
    /// <summary>角色移动</summary>
    public virtual void Move(float h, float v) { }
    /// <summary>控制是否开火</summary>
    public virtual void SetFire(bool on) { }
    /// <summary>角色死亡</summary>
    public virtual void die() { }
    /// <summary>开门或上车事件</summary>
    public virtual void OnEvent() { }
}
